import Notice from '../dll/notice'

/**

 * @author *琴
 * @mailbox 1570149578@qq.com
 * @company  四川英瑞世博电子商务有限公司
 * @date 2020-06-08 14:10
 * @http  https://********

 */
export default {
  data () {
    return {
      noticeList: [],
      page: 1,
      more: true
    }
  },

  created () {
    this.getNoticeList()
  },

  methods: {
    // 公告列表
    async getNoticeList () {
      if (!this.more) {
        return
      }
      let page = this.page
      let param = {
        page: page
      }
      this.$vux.loading.show({
        text: '加载中'
      })
      let res = await Notice.getNoticeList(param)
      this.$vux.loading.hide()
      if (res.code == 0) {
        if (page >= res.data.page_total) {
          this.more = false
          this.$refs.scroller && this.$refs.scroller.disablePullup()
        }
        this.noticeList = [].concat(this.noticeList, res.data.list)
        this.page = page + 1
        this.$forceUpdate()
        this.$refs.scroller && this.$refs.scroller.donePullup()
      } else {
        this.more = false
        this.$forceUpdate()
        this.$refs.scroller && this.$refs.scroller.disablePullup()
      }
    },

    // 进入公告详情
    onNoticeDetail (item) {
      this.$router.push({ name: 'noticeDetail', params: { id: item.n_id } })
    },

    // 进入公告列表
    onNotice () {
      this.$router.push({ name: 'notice' })
    }
  }
}
